package aga.sokoban;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import aga.sokoban.model.LevelCollection;
import aga.sokoban.model.LevelCollectionSerializer;
import android.content.res.AssetManager;

public class LevelProvider {
	private static final String DIR = "levels";

	private static ArrayList<LevelCollection> collections = new ArrayList<LevelCollection>();

	public static List<LevelCollection> getCollections() {
		return collections;
	}

	public static void init(AssetManager am) {
		LevelCollectionSerializer ser = new LevelCollectionSerializer();
		try {
			collections.clear();
			for (String str : am.list(DIR)) {
				InputStream in = am.open(DIR + "/" + str);
				LevelCollection collection = ser.load(in);
				collection.setName(str);
				collections.add(collection);
				break;
			}
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}
	}

//	public static LevelCollection getLevelCollection(String name) {
//		name = name.toLowerCase();
//		for (Layout l : getLayouts()) {
//			if (l.getName().equals(name))
//				return l;
//		}
//		throw new RuntimeException("Unknow layout: " + name);
//	}
}